/** Permutation */
#include<bits/stdc++.h>
using namespace std;
int n;
const int maxn = 10;
int vis;
vector<int> v;
void dfs(int dep) {
  if(dep==n+1) {
    for(auto el:v) {
      cout<<el<<' ';
    }
    cout<<endl;
    return;
  }
  for(int i=1; i<=n; ++i) {
    if(vis & 1<<i) continue;
    vis |= 1<<i;
    v.push_back(i);
    dfs(dep+1);
    vis &= ~(1<<i);
    v.pop_back();
  }
}
int main() {
  cin>>n;
  dfs(1);
}

